define(['jquery', 'bootstrap', 'utilback', 'table', 'form','ztree'], function ($, undefined, Utilback, Table, Form) {

    var Controller = {
    	config: {
    		get_dic: '/user/read/detail', // 获取用户详情
            get_param: '/param/read/detail',
    	},
        init: function () {
            this.initDic();
            this.initParam();
        },
        initDic:function(){
            $('[href="#dic"]').on('click',function(){
                // 初始化表格参数配置
                Table.api.init({
                    singleSelect: true,
                    showExport:false,
                    showToggle: false,
                    extend: {
                        index_url: './json/GYK.json', // 查询列表
                        add_url: 'dataUpgradeAdd.html', // 新增页面
                        edit_url: 'dataUpgradeAdd.html', // 修改页面
                        del_url: '/dataUpgrade', // 删除
                        multi_url: '/dataUpgrade',
                        fillIn_url:'dataUpgradeFillIn.html',
                    }
                });
            });
            $('[href="#dic"]').click();
             var table = $("#dicTable");
              // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                toolbar:'#toolbar1',
                method:'get',
                columns: [
                    [
                        {field: 'state', checkbox: true, },
                        {field: 'id', title: 'ID'},
                        {field: 'title', title: '升级标题'},
                        {field: 'explain', title: "升级说明"},
                        {field: 'upGride', title: "已升级网工区"},
                        {field: 'notUpGride', title: "未升级网工区"},
                        {field: 'upAccessory', title: "升级附件"},
                        {field: 'uptime', title: "升级有效日期"},
                        {field: 'upState', title: "升级状态"},
                        {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                return Table.api.formatter.operate.call(this, value, row, index, table);
                            }}
                    ]
                ]
            });
             // 为表格绑定事件
            Table.api.bindevent(table);
            // 填写反馈单
            $(".btn-fillIn").on('click',function(){
                var ids = Table.api.selectedids(table);
                var options = table.bootstrapTable('getOptions');
                    var url = options.extend.fillIn_url + (options.extend.fillIn_url.match(/(\?|&)+/) ? "&id=" : "?id=") + ids.join(",") + '&t=A';
                    Util.api.open(url, __('反馈单'));
            })
        },
        initParam:function(){
            var i = 0;
            $('[href="#param"]').on('click',function(){
                // 初始化表格参数配置
                Table.api.init({
                    singleSelect:true,
                    showExport:false,
                    showToggle: false,
                    extend:{
                        index_url: './json/GYK.json', // 查询列表
                        add_url: 'dataUpgradeAdd.html', // 新增页面
                        edit_url: 'dataUpgradeAdd.html', // 修改页面
                        del_url: '/dataUpgrade', // 删除
                        multi_url: '/dataUpgrade',
                    }
                });
                if(i===0){
                    var paramTable = $("#paramTable");
                    paramTable.bootstrapTable({
                        toolbar:"#toolbar2",
                        url:$.fn.bootstrapTable.defaults.extend.index_url,
                        method:'get',
                        columns:[
                            [
                                {field:'state',checkbox:true,},
                                {field:'id',title:'ID'},
                                {field:'basicData',title:'升级版本基本数据'},
                                {field:'procedure',title:'升级版本DML程序'},
                                {field:'workshop',title:'车间工区'},
                                {field:'carNum',title:'作业车车号'},
                                {field:'upgridTime',title:'升级时间'},
                                {field:'serviceCondition',title:'升级、使用情况'},
                                {field:'driverName',title:'升级司机名'},
                                {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: function (value, row, index) {
                                return Table.api.formatter.operate.call(this, value, row, index,paramTable);
                            }}
                            ]
                        ]
                    });
                    Table.api.bindevent(paramTable);
                    i++;
                }
            })
        },

        edit: function () { // 初始化编辑页面
        	
            Form.api.bindevent($("form[role=form]"));
            Form.api.fill($("form[role=form]"),'./json/person.json',1);
            Form.api.bindevent($("form[role=form]"));
            Util.api.initSelectTree({
                checkParent: true,
                parentEle: 'department',
                url: './json/list.json',
                data: JSON.stringify({keyword:''}),
                resetData: function(data) {
                   for(var i=0;i<data.length;i++) {
                       if(data[i].leaf == 0) {
                           data[i]['open'] = true;
                       }
                       data[i]['pId'] = data[i].parentId;
                       data[i]['name'] = data[i].deptName;
                   }
                   return data;
                }
            });
            var id = Util.api.query('id');
            var t = Util.api.query('t');
            if(id && t === 'U') {
                Form.api.fill($('#edit-form'), Controller.config.get_url, id, function(data) {
                });
            }
        },
        update: function() {
            Form.api.bindevent($("form[role=form]"));
        	Util.api.ajax({
        		type: 'GET',
        		// url: '/user/read/current'
                url:'',
        	}, function(data) {
        		$('#edit-form').autofill(data);
        	});
        }
    };
    return Controller;
      function changeAgentContent(){
            document.getElementById("inputFileAgent").value
     = document.getElementById("inputFile").value;
    }
  
});